<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/admin/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>评价管理</el-breadcrumb-item>
      <el-breadcrumb-item>评价图表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-page-header @back="goBack" content="选择商家">
      </el-page-header>
      <div id="main"></div>
    </el-card>
  </div>
</template>

<script>
import echarts from 'echarts'

export default {
  name: 'ShowReport3',
  data () {
    return {
      option: {
        title: {
          text: '菜品评分趋势'
        },
        legend: {
          data: ['评分', '评分趋势']
        },
        xAxis: [
          {
            data: []
          }
        ],
        yAxis: [
          {
            type: 'value',
            name: '评分',
            min: 0,
            max: 5,
            interval: 1
          }
        ],
        series: [
          {
            name: '评分',
            type: 'bar',
            data: [],
            itemStyle: {
              color: '#91cc75'
            }
          },
          {
            name: '评分趋势',
            type: 'line',
            data: [],
            itemStyle: {
              color: '#5470c6'
            }
          }
        ]
      }
    }
  },
  async mounted () {
    const myChart = echarts.init(document.getElementById('main'))
    const rid = { rid: this.$route.params.rid }
    const { data: res } = await this.$axios.get('/admin/restaurant/getComments', { params: rid })
    if (res.status !== 2000) {
      return this.$message.error('获取数据失败')
    }
    this.option.xAxis[0].data = res.data.months
    this.option.series[0].data = res.data.comments
    this.option.series[1].data = res.data.comments
    myChart.setOption(this.option)
  },
  methods: {
    goBack () {
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped>
#main {
  margin-top: 30px;
  width: 1300px;
  height: 400px;
}
</style>
